package com.sky.mapper;

import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    void insertDetails(List<OrderDetail> orderDetails);


    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    List<Orders> selectById(OrdersPageQueryDTO ordersPageQueryDTO);
@Select("select *from order_detail where order_id=#{id}")
    List<OrderDetail> selectDetailByOrderId(Long id);
@Select("select *from orders where user_id=#{currentId}")
    List<Orders> selectByUserId(Long currentId);

    void updateStatus(Long id);
@Select("select *from orders where id=#{id}")
    Orders selectByOrderId(Long id);
@Update("update orders set status=1 where id=#{id}")
    void updateStatusToOne(Long id);
@Select("select count(*) from orders where status=2")
    Integer selectTwo();
    @Select("select count(*) from orders where status=3")
    Integer selectThree();
    @Select("select count(*) from orders where status=4")
    Integer selectFour();

    void receive(OrdersConfirmDTO ordersConfirmDTO);
    @Update("update orders set status=4 where id=#{id}")
    void send(Long id);
    @Update("update orders set status=5,delivery_time=#{now} where id=#{id}")
    void complete(Long id, LocalDateTime now);
@Select("select *from orders where status=#{deliveryInProgress} and order_time < #{now}")
    List<Orders> selectByStatusFiveAndTime(Integer deliveryInProgress, LocalDateTime now);
@Select("select count(*) from orders where status=5 and order_time between #{start} and #{dead}")
    Integer validOrderCountList(LocalDateTime start, LocalDateTime dead);
    @Select("select count(*) from orders where order_time between #{start} and #{dead}")
    Integer orderCountList(LocalDateTime start, LocalDateTime dead);
}
